'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    const { DECIMAL } = Sequelize;
    
    // 检查rating字段是否已存在
    const tableInfo = await queryInterface.describeTable('suppliers');
    if (!tableInfo.rating) {
      // 在suppliers表中添加rating字段
      await queryInterface.addColumn('suppliers', 'rating', {
        type: DECIMAL(3, 2),
        allowNull: true,
        defaultValue: 0.00,
        comment: '供应商评分'
      });
    }
  },

  down: async (queryInterface, Sequelize) => {
    // 检查rating字段是否存在
    const tableInfo = await queryInterface.describeTable('suppliers');
    if (tableInfo.rating) {
      // 删除rating字段
      await queryInterface.removeColumn('suppliers', 'rating');
    }
  }
};